package com.aidex.web.controller.biz;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.BillInfoDetails;
import com.aidex.biz.service.BillInfoDetailsService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 对账详情Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/biz/bizBillInfoDetails")
public class BillInfoDetailsController extends BaseController
{
    @Autowired
    private BillInfoDetailsService billInfoDetailsService;

    /**
     * 查询对账详情列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfoDetails:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BillInfoDetails billInfoDetails, HttpServletRequest request, HttpServletResponse response)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            billInfoDetails.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
         }
        billInfoDetails.setPage(new PageDomain(request, response));
        return R.data(billInfoDetailsService.findPage(billInfoDetails));
    }

    /**
     * 获取对账详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfoDetails:query')")
    @GetMapping(value = "/{id}")
    public R<BillInfoDetails> detail(@PathVariable("id") String id)
    {
        return R.data(billInfoDetailsService.get(id));
    }

    /**
     * 新增对账详情
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfoDetails:add')")
    @Log(title = "对账详情", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BillInfoDetails billInfoDetails)
    {
        return R.status(billInfoDetailsService.save(billInfoDetails));
    }

    /**
     * 修改对账详情
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfoDetails:edit')")
    @Log(title = "对账详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BillInfoDetails billInfoDetails)
    {
        return R.status(billInfoDetailsService.save(billInfoDetails));
    }


    /**
     * 删除对账详情
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfoDetails:remove')")
    @Log(title = "对账详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(billInfoDetailsService.deleteBillInfoDetailsByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfoDetails:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(billInfoDetailsService.findMaxSort(new BillInfoDetails()));
    }

    /**
     * 导出对账详情列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBillInfoDetails:export')")
    @Log(title = "对账详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BillInfoDetails billInfoDetails)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    billInfoDetails.setCompanyId(null);
            }else{
                         billInfoDetails.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<BillInfoDetails> list = billInfoDetailsService.findList(billInfoDetails);
        ExcelUtil<BillInfoDetails> util = new ExcelUtil<BillInfoDetails>(BillInfoDetails.class);
        return util.exportExcel(list, "对账详情数据");
    }

}
